package com.rgst.realm;

import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;

import com.rgst.utils.Md5SaltTool;

/**
 * Created by tancw on 2019/12/6.
 */
public class CustomCredentialsMatcher extends SimpleCredentialsMatcher {

    @Override
    public boolean doCredentialsMatch(AuthenticationToken authcToken, AuthenticationInfo info) {
        UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
        Object inDbPassword = getCredentials(info);
        try {
            return Md5SaltTool.validPassword(token.getPassword(),(char[]) inDbPassword);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}
